<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>新建应收登记</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>应收编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="number" placeholder="请输入" disabled autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>应收类别</label>
                        <div class="layui-input-block">
                            <select id="shoutype" name="shoutype" lay-filter="shoutype" ></select>
                            <p class="error" id="shoutype_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>收款对象</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="faer" class="layui-input faer" onclick="openPage('../public/choose_dealcom.php?dom=faer&page=contract_cai','80%','80%')">
                            <div class="choose_div" id="faer" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=faer','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>款项摘要</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhai" id="zhai" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>应收金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="money" id="money" placeholder="请输入" autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">发票情况</label>
                        <div class="layui-input-block">
                            <div id="incqing"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">预计到账日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="dt" id="dt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <?php include '../public/upinfo.php'?>
        </div>


    </div>
</form>
<script>
    $("#commentForm").validate({
        rules: {
            money: {required: true},
            zhai: {required: true},
        },
        messages:{
            money: {required: "请输入"},
            zhai: {required: "请输入"},
        }
    });

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_income_ying_add}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;
                $("#number").val(data.number);

                var shoutype_str = '<option value="">请选择</option>';
                var shoutype = res.data.shoutype;
                for (var key in shoutype){
                    shoutype_str += '<option value="'+key+'">'+shoutype[key]+'</option>';
                }
                $("#shoutype").html(shoutype_str);

                xmselect_dan('incqing', res.data.incqing, '');

                initParseMoney();
                public_upload_file_load('upload_files');
                render_from();
            }
        });

        form.on('select(shoutype)', function(data){
            if(data.value == ''){
                $('#shoutype_error').show().text('请选择');
                $('#shoutype_error').parent().find('input').addClass('select_error');
            }else{
                $('#shoutype_error').hide();
                $('#shoutype_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('submit(add)', function(data){
            var validRes = $("#commentForm").valid();

            if(data.field.shoutype == ''){
                $('#shoutype_error').show().text('请选择');
                $('#shoutype_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#shoutype_error').hide();
                $('#shoutype_error').parent().find('input').removeClass('select_error');
            }


            data.field.faer = get_choose_val('faer');
            formValid('faer');
            if(data.field.faer == undefined || !data.field.faer){
                validRes = false;
            }

            if(!validRes){return false;}


            data = parseMoney(data);
            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_income_ying_add, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });

</script>
</body>
</html>
